package cn.wolfcode.domain;

import cn.hutool.core.date.BetweenFormater;
import cn.hutool.core.date.DateUtil;
import cn.wolfcode.enums.AppointmentStatusEnum;
import cn.wolfcode.enums.NoticeStatusEnum;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

@Setter
@Getter
public class Notice {
    /**
     * 表id
     */
    private Long id;

    /**
     * 公告标题
     */
    private String title;

    /**
     * 创建人id
     */
    private Employee employee;

    /**
     * 公告级别
     */
    private Long level;

    /**
     * 是否已读(1已读, 0未读)
     */
    private Boolean readstatus=false;

    /**
     * 发布状态(1已发布 ,0 未发布)
     */
    private Boolean status=false;

    /**
     * 创建时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime = new Date();

    /**
     * 公告内容
     */
    private String content;

    public String getStatusName() {
        return NoticeStatusEnum.findName(level);
    }

    public String toJson() {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("content", content);
        map.put("level", level);
        return JSON.toJSONString(map);
    }
    public String getMisTime(){
        if(createTime!=null){
            return DateUtil.formatBetween(new Date(),createTime, BetweenFormater.Level.MINUTE);
        }
        return null;
    }
}